package com.example.demo.config;

import org.jasypt.encryption.StringEncryptor;
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class JasyptConfig {
    
    // 暂时注释掉配置注入
    /*
    @Value("${jasypt.encryptor.password}")
    private String password;
    
    @Value("${jasypt.encryptor.algorithm}")
    private String algorithm;
    
    @Value("${jasypt.encryptor.key-obtention-iterations}")
    private String keyObtentionIterations;
    
    @Value("${jasypt.encryptor.pool-size}")
    private String poolSize;
    
    @Value("${jasypt.encryptor.provider-name}")
    private String providerName;
    
    @Value("${jasypt.encryptor.salt-generator-classname}")
    private String saltGeneratorClassName;
    
    @Value("${jasypt.encryptor.string-output-type}")
    private String stringOutputType;
    */
    
    @Bean("jasyptStringEncryptor")
    public StringEncryptor stringEncryptor() {
        PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
        SimpleStringPBEConfig config = new SimpleStringPBEConfig();
        // 使用默认值
        config.setPassword("default");
        config.setAlgorithm("PBEWithMD5AndDES");
        config.setKeyObtentionIterations("1000");
        config.setPoolSize("1");
        config.setProviderName("SunJCE");
        config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
        config.setStringOutputType("base64");
        encryptor.setConfig(config);
        return encryptor;
    }
} 